from google.appengine.ext import db
from google.appengine.ext import search

class UnicodeChar(search.SearchableModel):
  """A searchable unicode character model.
  
  From http://theory.uwinnipeg.ca/CPAN/perl/lib/Unicode/UCD.html:
  
  code             code point with at least four hexdigits
  name             name of the character IN UPPER CASE
  block            block the character belongs to
  category         general category of the character
  combining        classes used in the Canonical Ordering Algorithm
  bidi             bidirectional category
  decomposition    character decomposition mapping
  decimal          if decimal digit this is the integer numeric value
  digit            if digit this is the numeric value
  numeric          if numeric is the integer or rational numeric value
  mirrored         if mirrored in bidirectional text
  unicode10        Unicode 1.0 name if existed and different
  comment          ISO 10646 comment field
  upper            uppercase equivalent mapping
  lower            lowercase equivalent mapping
  title            titlecase equivalent mapping
  
  TODO: implement script?
  """
  code = db.IntegerProperty(verbose_name="Code value")
  name = db.StringProperty(verbose_name="Character name")
  html_entity = db.StringProperty(verbose_name="HTML entity")
  block = db.StringProperty(verbose_name="Unicode block name")
  category = db.StringProperty(verbose_name="General Category")
  category_code = db.StringProperty(verbose_name="General Category Code")
  block = db.StringProperty(verbose_name="Unicode Block")
  combining = db.IntegerProperty(verbose_name="Canonical Combining Classes")
  bidi = db.StringProperty(verbose_name="Bidirectional Category")
  bidi_code = db.StringProperty(verbose_name="Bidirectional Category Code")
  # TODO: Convert decomposition to a dictionary of keys?
  decomposition = db.StringProperty(verbose_name="Character Decomposition Mapping")
  decimal = db.IntegerProperty(verbose_name="Decimal digit value")
  digit = db.IntegerProperty(verbose_name="Digit value")
  # TODO: Convert this to a property that can interpret fractions
  numeric = db.StringProperty(verbose_name="Numeric value")
  mirrored = db.StringProperty(verbose_name="Mirrored")
  unicode10 = db.StringProperty(verbose_name="Unicode 1.0 name")
  comment = db.StringProperty(verbose_name="10646 comment field")
  # TODO: Convert these to ReferenceProperties?
  upper = db.IntegerProperty(verbose_name="Uppercase Mapping")
  lower = db.IntegerProperty(verbose_name="Lowercase Mapping")
  title = db.IntegerProperty(verbose_name="Titlecase Mapping")
